package com.nanfang51g3.ckz.ui.testui;

import com.nanfang51g3.ckz.utils.KLog;

import rx.Observable;
import rx.Subscriber;

/**
 * Created by Administrator on 2016/7/15.
 * 测试内存泄漏问题 未在耗时操作线程切换
 */
public class RxTest {

    public Observable<String> textRx() {
        return Observable.create(new Observable.OnSubscribe<String>() {
            @Override
            public void call(final Subscriber<? super String> subscriber) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        String result = loadTime();
                        subscriber.onNext(result);
                        subscriber.onCompleted();
                    }
                }).start();

            }
        });
    }

    public String loadTime() {
        String result = "";
        int i = 0;
        try {
            while (i < 50) {
                i++;
                Thread.sleep(1000);
                KLog.i("Evd", "loadTime = " + i);
            }
            result = "执行完毕...";
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return result;
    }
}
